package pe.edu.upc.dsd.whereeat.domain;

import java.io.Serializable;
import javax.persistence.*;
import javax.xml.bind.annotation.XmlRootElement;

import pe.edu.upc.dsd.whereeat.base.domain.BaseEntity;

import java.util.Date;
import java.util.List;

/**
 * The persistent class for the restaurant database table.
 * 
 */
@Entity
@Table(name = "restaurant")
@XmlRootElement
public class Restaurant extends BaseEntity implements Serializable {
	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	@Column(unique = true, nullable = false)
	private int codigo;

	@Column(length = 100)
	private String descripcion;

	@Column(length = 1)
	private String estado;

	@Temporal(TemporalType.TIMESTAMP)
	private Date fecha;

	@Column(length = 50)
	private String nombre;

	// bi-directional many-to-one association to Calificacion
	@OneToMany(mappedBy = "restaurant", cascade = { CascadeType.ALL })
	private List<Calificacion> calificacions;
 
	// bi-directional many-to-one association to Local

	@OneToMany(mappedBy="restaurant", fetch=FetchType.LAZY)
	//@OneToMany(cascade = CascadeType.ALL)
	//@JoinTable(name = "Restaurant", joinColumns = { @JoinColumn(name = "codigo", unique = true) }, inverseJoinColumns = { @JoinColumn(name = "codigoRestaurant") })
	private List<Local> locals;

	// bi-directional many-to-one association to Plato
	@OneToMany(mappedBy = "restaurant",fetch=FetchType.LAZY)
	private List<Plato> platos;

	// bi-directional many-to-one association to Categoria
	@ManyToOne(cascade = { CascadeType.DETACH }, fetch = FetchType.LAZY)
	@JoinColumn(name = "codigoCategoria")
	private Categoria categoria;

	public Restaurant() {
	}

	public Restaurant(int codigo) {
		this.codigo = codigo;
	}

	public int getCodigo() {
		return this.codigo;
	}

	public void setCodigo(int codigo) {
		this.codigo = codigo;
	}

	public String getDescripcion() {
		return this.descripcion;
	}

	public void setDescripcion(String descripcion) {
		this.descripcion = descripcion;
	}

	public String getEstado() {
		return this.estado;
	}

	public void setEstado(String estado) {
		this.estado = estado;
	}

	public Date getFecha() {
		return this.fecha;
	}

	public void setFecha(Date fecha) {
		this.fecha = fecha;
	}

	public String getNombre() {
		return this.nombre;
	}

	public void setNombre(String nombre) {
		this.nombre = nombre;
	}

	public List<Calificacion> getCalificacions() {
		return this.calificacions;
	}

	public void setCalificacions(List<Calificacion> calificacions) {
		this.calificacions = calificacions;
	}

	public List<Local> getLocals() {
		return this.locals;
	}

	public void setLocals(List<Local> locals) {
		this.locals = locals;
	}

	public List<Plato> getPlatos() {
		return this.platos;
	}

	public void setPlatos(List<Plato> platos) {
		this.platos = platos;
	}
	 @ManyToOne(cascade = { CascadeType.PERSIST, CascadeType.MERGE })
	public Categoria getCategoria() {
		return this.categoria;
	}

	public void setCategoria(Categoria categoria) {
		this.categoria = categoria;
	}

}